Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement autodetection for default compiler from NDK #495

Merged
merged 1 commit into from
May 14, 2020

Conversation

Dushistov
Copy link
Contributor

@Dushistov Dushistov commented May 9, 2020

ref #459

Long time ago you had to extract compiler from Android NDK to make it standalone and usable as linker/c/c++ compiler (for example process described here https://mozilla.github.io/firefox-browser-architecture/experiments/2017-09-21-rust-on-android.html).

At now you can use default C/C++ compiler without efforts. But naming for compilers are different now. For example before this patch, cc-rs try to find arm-linux-androideabi-clang, but default compiler now is armv7a-linux-androideabi16-clang. Also new clang compiler doesn't define things like ANDROID/__ANDROID_API__ so it should be defined manually.

Without this patch I can not compile rusqlite for android:

//Cargo.toml
[dependencies]
rusqlite = { version = "0.17.0", features = ["chrono", "functions", "bundled"] }
//.cargo/config
[target.armv7-linux-androideabi]
linker = "armv7a-linux-androideabi16-clang"

it prints:

error occurred: Failed to find tool. Is `arm-linux-androideabi-clang` installed?

@Dushistov Dushistov force-pushed the fix-build-with-new-ndk branch from 724afc7 to 110e038 Compare May 9, 2020 15:34
src/lib.rs Outdated Show resolved Hide resolved
src/lib.rs Show resolved Hide resolved
@Dushistov Dushistov force-pushed the fix-build-with-new-ndk branch from 110e038 to 8c40bad Compare May 12, 2020 10:39
.replace("armv7neon", "arm")
.replace("armv7", "arm")
.replace("thumbv7neon", "arm")
.replace("thumbv7", "arm");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW this normalization isn't used when trying to find a new compiler, could this be refactored a bit such that these rustc targets would still find the armv7a android compiler?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I intentionally did not touch this code. Tier 1,2 platforms have only linux+android support. So it is hard test for Windows and MacOS, but code bellow works with windows, so I avoid changing anything that I can not test.

Plus I don't think that this is refactoring is possible. IMHO new target naming that include android API level was introduced recently, so if somebody do not want update Android NDK and uses old clang it is easy enough to break things for them.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My point is that the armv7-linux-androideabi target, if folks are using it, will not hit the new clang compiler when it very likely should. I don't think there's a lot of risk here, it's basically just moving this let target block up to the top of the function instead of having it at the bottom

Copy link
Contributor Author

@Dushistov Dushistov May 13, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My point is that the armv7-linux-androideabi target, if folks are using it, will not hit the new
clang compiler when it very likely should.

@alexcrichton, not sure that I understand you. armv7-linux-androideabi mapped to Some("armv7a") and then to armv7a-linux-androideabi16-clang call.
So armv7-linux-androideabi hit the new clang compiler, it is my main testing configuration,
I built all my code with cargo build --target=armv7-linux-androideabi and ran on android device before submitting this PR.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah ok I think I was misreading a bit. In any case we can always tweak this later!

src/lib.rs Outdated Show resolved Hide resolved
src/lib.rs Show resolved Hide resolved
src/lib.rs Show resolved Hide resolved
@Dushistov Dushistov force-pushed the fix-build-with-new-ndk branch from 8c40bad to af713db Compare May 12, 2020 19:47
@Dushistov Dushistov force-pushed the fix-build-with-new-ndk branch from af713db to f952e20 Compare May 13, 2020 21:23
@alexcrichton alexcrichton merged commit d20f57b into rust-lang:master May 14, 2020
@alexcrichton
Copy link
Member

Thanks again!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants